import {
  fetchValidateTOken,
  setPlatformId,
  setUserId,
} from "./api/server/recommend_question";
import { initRoot } from "./bootstrap";
import { parseSearchToObject } from "./utils";

const searchObj = parseSearchToObject(location.search);

if (searchObj.token) {
  fetchValidateTOken(searchObj.token)
    .then((res) => {
      // console.log(res);
      // const info = {
      //   success: true,
      //   results: {
      //     user_id: "1234",
      //     platform_id: "BaihuaYongGongXia",
      //     exp: 1734528247,
      //   },
      // };

      const info = res.data;
      setUserId(info?.results?.user_id);
      setPlatformId(info?.results?.platform_id);
      initRoot();
    })
    .catch((err) => {
      console.log(err);
      initRoot();
    });
} else {
  initRoot();
}
